<!--结算栏-->
<template>
  <div class="page-container main">
    <!--<div class="tool-container">
         <el-form-item v-if="dict.settle_contents!=null">
          <el-select v-model="queryParams.itemType" filterable placeholder="结算项目" clearable style="width: 240px">
            <el-option v-for="item in dict.settle_contents" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item>          
          <el-date-picker v-model="queryParams.createTime" type="date" format="YYYY-MM-DD" placeholder="结算日期" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form> 
    </div>-->

    <div class="tabel-container myTable">
      <vxe-table ref="tableRef" :data="tableData" v-loading="loading">
        <vxe-table-column :resizable="true" type="seq" title="序号" width="80" sortable></vxe-table-column>
        <vxe-table-column :resizable="true" field="itemType" title="结算内容" sortable>
          <template #default="{ row }">
            <dict-tag :options="dict.settle_contents" :value="row.itemType" />
          </template>
        </vxe-table-column>
        <vxe-table-column :resizable="true" field="status" title="结算状态" sortable>
          <template #default="{ row }">
            <dict-tag :options="dict.settle_status" :value="row.status" />
          </template>
        </vxe-table-column>
        <vxe-table-column :resizable="true" field="itemAmount" title="结算金额" sortable>
          <template #default="{ row }"> {{row.itemAmount/100.0}} 元 </template>
        </vxe-table-column>
        <vxe-table-column :resizable="true" field="createTime" title="结算时间" sortable> </vxe-table-column>
      </vxe-table>
    </div>
    <div class="myPager">
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>
  </div>
</template>

<script lang="ts">
import { jsList } from '@/api/operation/vendorSettlement/index';

import common from '@/utils/common.ts';

export default {
  props: {
    data: {}
  },
  computed: {
    times: {
      get() {
        return [this.queryParams.timeFrom, this.queryParams.timeTo];
      },
      set(value) {
        this.queryParams.timeFrom = value[0];
        this.queryParams.timeTo = value[1];
      }
    }
  },
  data() {
    return {
      proxy: null,
      dict: {},
      loading: false,
      users: [],
      tableData: [],
      total: 1,
      queryParams: {
        settlementId: null,
        createTime: '',
        timeFrom: '',
        timeTo: '',
        pageNum: 1,
        pageSize: 20
      }
    };
  },
  mounted() {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;
    this.proxy = proxy;
    this.dict = toRefs<any>(this.proxy?.useDict('settle_status', 'settle_contents'));

    this.init();
  },
  methods: {
    init(data) {
      // if (data == null) data = this.data;
      // this.queryParams.activityId = data.activityId;
      this.getList();
    },

    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /**
     * 查询数据
     */
    getList() {
      this.loading = true;
      jsList(this.queryParams).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData = res.rows;
        } else {
          ElMessage.error(res.msg);
        }
      });
    },

    /**
     * 获取用户列表
     */
    queryUserList(name) {
      listUser({ nickName: name }).then((res) => {
        if (res.code == 200) {
          this.users = res.rows;
        }
      });
    },

    /**
     * 匹配结果
     */
    marchType(value, types) {
      for (let i = 0; i < types.length; i++) {
        let type = types[i];
        if (type.value == value) return type.label;
      }
    }
  }
};
</script>
